package com.msb.servicemap.remote;

import com.msb.internalcommon.constant.AmapConfigConstants;
import com.msb.internalcommon.dto.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * @Auther: jiudianliu
 * @Date: 2023/6/9 - 06 - 09 - 16:10
 * @Description: com.msb.servicemap.remote
 * @version: 1.0
 */
@Service
public class MapDicDistrictClient {

    @Value("${map.key}")
    private String mapKey ;

    @Autowired
    private RestTemplate restTemplate ;


    public String  DicDistrict(String keywords){

        //拼装请求的url
        //网址示例：?keywords=北京&subdistrict=2&key=<用户的key>
        StringBuilder url = new StringBuilder();
        url.append(AmapConfigConstants.DISTRICT_URL);
        url.append("?");
        url.append("keywords=" + keywords);
        url.append("&");
        url.append("subdistrict=3");
        url.append("&");
        url.append("key=" + mapKey);
        ResponseEntity<String> forEntity = restTemplate.getForEntity(url.toString(), String.class);
        return forEntity.getBody();
    }
}
